<template>
	<view class="container">
		<index-header></index-header>
		<index-banner></index-banner>
		<menu-list></menu-list>
		<static-banner></static-banner>
		<limited-seckill></limited-seckill>
	</view>
</template>

<script>
	import IndexHeader from "../../components/index/IndexHeader.vue"
	import IndexBanner from "../../components/index/IndexBanner.vue"
	import MenuList from "../../components/index/ItemList.vue"
	import StaticBanner from "../../components/index/StaticBanner.vue"
	import LimitedSeckill from "../../components/index/LimitedSeckill.vue"
	export default {
		data() {
			return {
				
			}
		},
		components: {
			IndexHeader,
			IndexBanner,
			MenuList,
			StaticBanner,
			LimitedSeckill,
		},
		onShow() {
			this.getopenid()
		},
		methods: {
			// 获取openid
			async getopenid() {
				let self = this
				uni.login({
					async success(res) {
						// console.log();
						let ret = await self.$Request("/port/getopenid",{ code: res.code })
						// console.log(ret);
						let errcode = ret.data.data.errCode
						if(errcode) {
							self.$store.commit("getopenid", {})
						} else {
							self.$store.commit("getopenid", ret.data.data)
							 // console.log(self.$store.state.userData.openid);
							self.getUserToken( self.$store.state.userData.openid)
						}
					}
				})
			},
			// 使用openid获取token
			async getUserToken( openid ) {
				let res = await this.$Request("/port/getUserToken", { openid })
				// console.log(res);
				let code = res.data.code 
				if(code == 200) {
					this.$store.commit("getToken", res.data.data)
				}
			}
		},
	}
</script>

<style>
	.container {
		width: 100%;
		box-sizing: border-box;
		overflow: hidden;
		background-color: #F5F5F5;
	}
</style>
